package cn.com.filemanager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * @author zhaokk
 * @since 2024/7/20
 */
@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建File对象，指向文件上传的目录
        File file = new File(SystemConfig.getConfig().get("upload_path"));
        //获取该目录下的文件列表
        String[] list = file.list();
        //将文件列表存到request作用域
        req.setAttribute("list", list);
        //转发到index.jsp
        req.getRequestDispatcher("index.jsp").forward(req, resp);
    }

}
